<template>
  <div class="app-container">
    <!-- 高级查询 -->
    <el-form v-show="searchVisible" ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item label="LOT所属仓位编码:">
        <el-input v-model="queryParams.lotCd" size="small" placeholder="请输入LOT所属仓位编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="cell编码原来主键:">
        <el-input v-model="queryParams.cellNo" size="small" placeholder="请输入cell编码原来主键" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="所属仓库编码:">
        <el-input v-model="queryParams.whCd" size="small" placeholder="请输入所属仓库编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="最大体积:">
        <el-input v-model="queryParams.maxVol" size="small" placeholder="请输入最大体积" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="最大仓储重量:">
        <el-input v-model="queryParams.maxCapacity" size="small" placeholder="请输入最大仓储重量" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="宽:">
        <el-input v-model="queryParams.width" size="small" placeholder="请输入宽" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="高:">
        <el-input v-model="queryParams.hight" size="small" placeholder="请输入高" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="长:">
        <el-input v-model="queryParams.length" size="small" placeholder="请输入长" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="域编码:">
        <el-input v-model="queryParams.site" size="small" placeholder="请输入域编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="版本号:">
        <el-input v-model="queryParams.version" size="small" placeholder="请输入版本号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="平均承重:">
        <el-input v-model="queryParams.avaCapacity" size="small" placeholder="请输入平均承重" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="平均体积:">
        <el-input v-model="queryParams.avaVol" size="small" placeholder="请输入平均体积" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="拣货指数:">
        <el-input v-model="queryParams.pickIndex" size="small" placeholder="请输入拣货指数" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="层数:">
        <el-input v-model="queryParams.storageLevel" size="small" placeholder="请输入层数" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="创建时间:">
        <el-date-picker v-model="queryParams.createDate" type="date" value-format="yyyy-MM-dd" size="small" placeholder="选择创建时间" clearable />
      </el-form-item>
      <el-form-item label="更新时间:">
        <el-date-picker v-model="queryParams.updateDate" type="date" value-format="yyyy-MM-dd" size="small" placeholder="选择更新时间" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermission="['web:tWhCellTb:insert']" type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['web:tWhCellTb:update']" type="success" icon="el-icon-edit" size="mini" :disabled="isSingle" @click="handleEdit">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['web:tWhCellTb:delete']" type="danger" icon="el-icon-delete" size="mini" :disabled="isMultiple" @click="handleRemove">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['web:tWhCellTb:export']" type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="searchVisible" @queryTable="handleQuery" />
    </el-row>

    <!-- 数据列表 -->
    <el-table v-loading="loading" :data="page.records" highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="LOT所属仓位编码" align="center" prop="lotCd" />
      <el-table-column label="cell编码原来主键" align="center" prop="cellNo" />
      <el-table-column label="所属仓库编码" align="center" prop="whCd" />
      <el-table-column label="最大体积" align="center" prop="maxVol" />
      <el-table-column label="最大仓储重量" align="center" prop="maxCapacity" />
      <el-table-column label="宽" align="center" prop="width" />
      <el-table-column label="高" align="center" prop="hight" />
      <el-table-column label="长" align="center" prop="length" />
      <el-table-column label="域编码" align="center" prop="site" />
      <el-table-column label="版本号" align="center" prop="version" />
      <el-table-column label="平均承重" align="center" prop="avaCapacity" />
      <el-table-column label="平均体积" align="center" prop="avaVol" />
      <el-table-column label="cell 类型" align="center" prop="cellType" />
      <el-table-column label="拣货指数" align="center" prop="pickIndex" />
      <el-table-column label="层数" align="center" prop="storageLevel" />
      <el-table-column label="记录 ID，系统自动产生" align="center" prop="id" />
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-hasPermission="['web:tWhCellTb:update']" size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">修改</el-button>
          <el-button v-hasPermission="['web:tWhCellTb:delete']" size="mini" type="text" icon="el-icon-delete" @click="handleRemove(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination v-show="page.total>0" :total="page.total" :page.sync="page.current" :limit.sync="page.pageSize" @pagination="handleQuery" />

    <!-- 添加/修改对话框 -->
    <el-dialog :title="tWhCellTbFormDialog.title" :visible.sync="tWhCellTbFormDialog.visible" :close-on-click-modal="false" :before-close="resetTWhCellTbFormDialog" width="500px" append-to-body>
      <el-form ref="tWhCellTbForm" :model="tWhCellTbFormData" :rules="tWhCellTbFormRules" label-width="80px">
        <el-form-item label="LOT所属仓位编码" prop="lotCd">
          <el-input v-model="tWhCellTbFormData.lotCd" placeholder="请输入LOT所属仓位编码" />
        </el-form-item>
        <el-form-item label="cell编码原来主键" prop="cellNo">
          <el-input v-model="tWhCellTbFormData.cellNo" placeholder="请输入cell编码原来主键" />
        </el-form-item>
        <el-form-item label="所属仓库编码" prop="whCd">
          <el-input v-model="tWhCellTbFormData.whCd" placeholder="请输入所属仓库编码" />
        </el-form-item>
        <el-form-item label="最大体积" prop="maxVol">
          <el-input v-model="tWhCellTbFormData.maxVol" placeholder="请输入最大体积" />
        </el-form-item>
        <el-form-item label="最大仓储重量" prop="maxCapacity">
          <el-input v-model="tWhCellTbFormData.maxCapacity" placeholder="请输入最大仓储重量" />
        </el-form-item>
        <el-form-item label="宽" prop="width">
          <el-input v-model="tWhCellTbFormData.width" placeholder="请输入宽" />
        </el-form-item>
        <el-form-item label="高" prop="hight">
          <el-input v-model="tWhCellTbFormData.hight" placeholder="请输入高" />
        </el-form-item>
        <el-form-item label="长" prop="length">
          <el-input v-model="tWhCellTbFormData.length" placeholder="请输入长" />
        </el-form-item>
        <el-form-item label="域编码" prop="site">
          <el-input v-model="tWhCellTbFormData.site" placeholder="请输入域编码" />
        </el-form-item>
        <el-form-item label="版本号" prop="version">
          <el-input v-model="tWhCellTbFormData.version" placeholder="请输入版本号" />
        </el-form-item>
        <el-form-item label="平均承重" prop="avaCapacity">
          <el-input v-model="tWhCellTbFormData.avaCapacity" placeholder="请输入平均承重" />
        </el-form-item>
        <el-form-item label="平均体积" prop="avaVol">
          <el-input v-model="tWhCellTbFormData.avaVol" placeholder="请输入平均体积" />
        </el-form-item>
        <el-form-item label="拣货指数" prop="pickIndex">
          <el-input v-model="tWhCellTbFormData.pickIndex" placeholder="请输入拣货指数" />
        </el-form-item>
        <el-form-item label="层数" prop="storageLevel">
          <el-input v-model="tWhCellTbFormData.storageLevel" placeholder="请输入层数" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createDate">
          <el-date-picker v-model="tWhCellTbFormData.createDate" type="date" value-format="yyyy-MM-dd" size="small" style="width: 100%" placeholder="选择创建时间" clearable />
        </el-form-item>
        <el-form-item label="更新时间" prop="updateDate">
          <el-date-picker v-model="tWhCellTbFormData.updateDate" type="date" value-format="yyyy-MM-dd" size="small" style="width: 100%" placeholder="选择更新时间" clearable />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmTWhCellTbFormDialog">确 定</el-button>
        <el-button @click="resetTWhCellTbFormDialog">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import TWhCellTbApi from '@/api/web/TWhCellTbApi'

const defaultTWhCellTbFormData = {
  lotCd: null,
  cellNo: null,
  whCd: null,
  maxVol: null,
  maxCapacity: null,
  width: null,
  hight: null,
  length: null,
  site: null,
  version: null,
  avaCapacity: null,
  avaVol: null,
  cellType: null,
  pickIndex: null,
  storageLevel: null,
  createDate: null,
  updateDate: null,
}
export default {
  name: 'TWhCellTbList',
  data() {
    return {
      options: {
        sysYnTypeOptions: this.$constant.sysYnTypeOptions
      },
      queryParams: {
        lotCd: null,
        cellNo: null,
        whCd: null,
        maxVol: null,
        maxCapacity: null,
        width: null,
        hight: null,
        length: null,
        site: null,
        version: null,
        avaCapacity: null,
        avaVol: null,
        cellType: null,
        pickIndex: null,
        storageLevel: null,
        createDate: null,
        updateDate: null,
        isValid: this.$constant.Y
      },
      page: {
        current: 1,
        pageSize: 10,
        total: 0,
        records: []
      },
      tWhCellTbFormDialog: {
        title: '',
        visible: false
      },
      tWhCellTbFormData: Object.assign({}, defaultTWhCellTbFormData),
      tWhCellTbFormRules: {
        lotCd: [{ required: true, message: 'LOT所属仓位编码不能为空', trigger: 'blur' }],

        cellNo: [{ required: true, message: 'cell编码原来主键不能为空', trigger: 'blur' }],

        version: [{ required: true, message: '版本号不能为空', trigger: 'blur' }],

        createDate: [{ required: true, message: '创建时间不能为空', trigger: 'blur' }],

        updateDate: [{ required: true, message: '更新时间不能为空', trigger: 'blur' }],

      },
      loading: true,
      searchVisible: true,
      multipleSelection: [],
      isSingle: true,
      isMultiple: true
    }
  },
  created() {
    this.handleQuery()
    this.loadOptions()
  },
  methods: {
    loadOptions() {
    },
    handleAdd() {
      this.openTWhCellTbFormDialog()
    },
    handleRemove(row) {
      const ids = row.id || this.multipleSelection.map(item => item.id)
      this.$confirm('是否确认删除数据?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return TWhCellTbApi.remove(ids)
      }).then(() => {
        this.handleQuery()
        this.$message.success('删除成功')
      })
    },
    handleEdit(row) {
      const id = row.id || this.multipleSelection.map(item => item.id)[0]
      this.openTWhCellTbFormDialog(id)
    },
    handleQuery() {
      this.loading = true
      TWhCellTbApi.page(this.queryParams, this.page).then(response => {
        this.page.records = response.data.records
        this.page.total = response.data.total
        this.loading = false
      }, () => {
        this.loading = false
      })
    },
    handleExport() {
      this.$confirm('是否确认导出数据?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return TWhCellTbApi.exportData(this.queryParams)
      }).then(response => {
        this.$common.download(response.msg)
      })
    },
    openTWhCellTbFormDialog(id) {
      this.tWhCellTbFormDialog.visible = true
      if (id) {
        this.tWhCellTbFormDialog.title = '仓库库存单元-修改'
        TWhCellTbApi.get(id).then(response => {
          this.tWhCellTbFormData = {
            ...this.tWhCellTbFormData,
            ...response.data
          }
        })
      } else {
        this.tWhCellTbFormDialog.title = '仓库库存单元-添加'
      }
    },
    confirmTWhCellTbFormDialog() {
      this.$refs['tWhCellTbForm'].validate(valid => {
        if (valid) {
          if (this.tWhCellTbFormData.id) {
            TWhCellTbApi.edit(this.tWhCellTbFormData).then(response => {
              this.$message.success('修改成功')
              this.resetTWhCellTbFormDialog()
              this.handleQuery()
            })
          } else {
            TWhCellTbApi.add(this.tWhCellTbFormData).then(response => {
              this.$message.success('添加成功')
              this.resetTWhCellTbFormDialog()
              this.handleQuery()
            })
          }
        }
      })
    },
    resetTWhCellTbFormDialog() {
      this.tWhCellTbFormDialog = {
        title: '',
        visible: false
      }
      this.tWhCellTbFormData = Object.assign({}, defaultTWhCellTbFormData)
      this.resetForm('tWhCellTbForm')
    },
    handleSelectionChange(selection) {
      this.multipleSelection = selection
      this.isSingle = selection.length !== 1
      this.isMultiple = !selection.length
    },
    resetQuery() {
      this.page.current = 1
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
